package cn.yx.common.security.properties;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * <p>SecurityProperties配置类，对应JwtToken的配置和验证码相关的配置</p>
 *
 * @author Wgssmart
 */
@Component
@ConfigurationProperties("security.config")
@Getter
@Setter
public class SecurityProperties {

    /**
     * 登录处理URL
     */
    private String loginProcessUrl = "/auth/login/verify-code";

    /**
     * 未登录时的跳转URL
     */
    private String authRequireUrl = "/auth/require";

    /**
     * JwtToken配置
     */
    private JwtToken jwtToken = new JwtToken();
    /**
     * 普通验证码配置
     */
    private VerifyCode verifyCode = new VerifyCode();
    /**
     * 短信验证码配置
     */
    private SmsCode smsCode = new SmsCode();

    @Getter
    @Setter
    public static class JwtToken {
        /**
         * Http请求头
         */
        private String header = "Authorization";
        /**
         * jwt token请求头前缀
         */
        private String headerPrefix = "Bearer ";
        /**
         * jwt token失效时间，单位为天
         */
        private Integer expiration = 30;
        /**
         * jwt token缓存失效时间，单位为小时
         */
        private Integer cacheExpiration = 24;

    }

    @Getter
    @Setter
    public static class VerifyCode {
        /**
         * 使用普通验证码登录时的URL
         */
        private String loginUrl = "/auth/login/verify-code";
        /**
         * 验证码长度
         */
        private Integer verifyCodeLength = 6;
        /**
         * 验证码失效时间，单位为分钟
         */
        private Integer verifyCodeExpiration = 5;
        /**
         * 会话cookie name
         */
        private String sessionName = "sessionId";
        /**
         * 验证码请求参数名称
         */
        private String verifyCodeParamName = "verifyCode";
    }

    @Getter
    @Setter
    public static class SmsCode {
        /**
         * 使用短信验证码登录时的URL
         */
        private String loginUrl = "/auth/login/sms-code";
        /**
         * 短信验证码长度
         */
        private Integer smsCodeLength = 6;
        /**
         * 短信验证码失效时间，单位为分钟
         */
        private Integer smsCodeExpiration = 5;
        /**
         * 短信验证码登录时的手机号请求参数名
         */
        private String phoneParamName = "phone";
        /**
         * 短信验证码登录时的验证码请求参数名
         */
        private String smsCodeParamName = "smsCode";
    }

}
